﻿<p class="bold large">Write the method arrSum that takes in an array of integers as a parameter, adds the values, and returns the total</p>
<p>If [1, 3, 4, 2, 5] were passed in then 15 would be returned</p>
<p>If [] were passed in then 0 would be returned</p>
<div class="practiceAccordion">
    <h3>Hints</h3>
    <div>
        <ul>
            <li>Start with a variable that you can add all the values to (i.e. have a sum variable)</li>
            <li>You will need to write a loop that traverses the array and adds each 
            element to the sum variable</li>
            <li>Return the sum variable at the end of the method (don't print)</li>
        </ul>
    </div>
    <h3>Possible Solution</h3>
<p class="format code">public static int arrSum(int[] arr) {
    int sum = 0;

    for(int i = 0; i &#60 arr.length; i++) {
        sum += arr[i];
    }

    return sum;
}
</p>
            </div> 
<a href="#practiceTop">Back to top</a>